{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### PROBLEMS  \n",
    "- TODO- Too few active LORs (i.e. pet.load_listmode_file(n_events=1000)  -> pet.project FAILS (don’t know why).\n",
    "\n",
    "#### IMPROVEMENTS: \n",
    "- TODO- Simplify names of functions and make them more consistent: e.g. pet.set_activity_size(), pet.set_activity_shape()\n",
    "- TODO- Use SI unit measures for activity, attenuation, distance \n",
    "- TODO- Adaptive box for projection and back-projection - auto-calibration step  \n",
    "- TODO- Optionally change integration method: rectangle rule, trapezoidal rule, Simpson’s rule\n",
    "- TODO- Get rid of class ROI and use Image3D and its Affine matrix to represent activity and attenuation. \n",
    "- TODO- Fix PET_Dynamic_Scan \n",
    "- TODO- Compressed measurements, uncompressed sensitivity \n",
    "- TODO- Implement fast low-resolution reconstruction - using sensitivity. \n",
    "- TODO- Compute the derivative of log likelihood with respect to the motion parameters \n",
    "- TODO- Implement new design: definition of the scanner geometry and interface / binning / span / list-mode binning \n",
    "- TODO- implement ray-tracer for list-mode binning \n",
    " \n",
    "#### TESTS: \n",
    "- TODO- reconstruct pineapple with exact azimuthal angles \n",
    "- TODO- verify that the projector and backprojector match exactly when rotating azimuthally only\n",
    "- TODO- implement test conjugancy projector http://math.stackexchange.com/questions/252655/verifying-the-transpose-of-a-linear-operator \n",
    "\n",
    "##### sensitivity: \n",
    "- DONE- verify that the black lines in the sensitivity match the measurement, e.g. pineapple\n",
    "- DONE- do we have a measurement with broken crystal ? Use it to verify the alignment of the sensitivity \n",
    "- DONE- verify that the sensitivity improves the image quality: e.g. brain image \n",
    "\n",
    "#####  unit testing: \n",
    "- TODO- integrate the tests in occiput.io unit testing \n",
    "\n",
    "\n",
    "#### DEVELOPMENT: \n",
    "\n",
    "##### Version 1.0:\n",
    "\n",
    "- V - import_volume and export_volume in DataSources \n",
    "- V - unify import, load, export, save: use file extension \n",
    "- V - fix 0-180.0  to  0-180.0 minus delta  in angles axial\n",
    "- V - study current setup: what defines a scanner? What defines a scanner geometry?  What defines a list-mode stream? What defines meshing? \n",
    "- V - simplify interface PET \n",
    "- V - span and binning - do it right \n",
    "- V - listmode streaming and conversion - do it right \n",
    "- V - scanner geometries \n",
    "- V - separate projection_activity and projection_attenuation \n",
    "- V - allow for different size, shape and orientation of activity and attenuation: \n",
    "- V - use also different parameters of the projector and back-projector: step_size, n_points \n",
    "- V - fix .to_nd_array() and .data: \n",
    "- V - Now things are different when the data is loaded from list-mode, from h5 and from interfile \n",
    "- V - handle both sparse and full sampling gracefully: use .data when no compression to simplify the use and .to_nd_array() == .data\n",
    "- V - load listmode: FIX and separate compression and decompression \n",
    "- V - use_compression(): call it at any time \n",
    "- V - overload methods for division, multiplication, .. volumes and projections \n",
    "- V - implement gradients and estimate_activity \n",
    "- V - OSEM PET \n",
    "- V - Generic PET scanner demo reconstruction  \n",
    "- V - change volume size - demo \n",
    "- V - implement gradient_activity \n",
    "- V - implement estimate_activity \n",
    "- V - understand the unit measure of the scale_activity parameter \n",
    "- V  - verify that the scale is ok when changing the volume size \n",
    "-    - make sure scale is correct in attenuation back-projection\n",
    "-    - get rid of N_axial and N_azimuthal in Binning \n",
    "-    - implement gradient attenuation \n",
    "- V  - estimate attenuation, estimate activity and attenuation \n",
    "\n",
    "-   .2- implement compression (now only uncompression - compressed structure is created only when loading listmode). Find zeros. Low level. \n",
    "-   .2- move all structures for 3D and 4D compressed data in NiftyRec and remove from Occiput_Scanner_Biograph_mMR \n",
    "- V .2- reduce computational cost add, sub, mul, div projections when fully sampled: use subsets_matrix \n",
    "-   .2- reduce computational cost projection: bounding box - implement it using the sparsity pattern: project FOV \n",
    "- V .2- Memoization of attenuation, projection of attenuation, att_sens and other pre-calculations - compatible with sparsity and subsets_matrix \n",
    "-   .2- import and export projection data: these functions need the Michelogram: tidy up \n",
    "-   .2- do OSEM using FOVEA: grid within a projection plane, possibly not uniform \n",
    " \n",
    "-   .3- eliminate ROI and use Image3D, grid and transformation parameters \n",
    "-   .3- translate and rotate recon volume - demo \n",
    "-   .3- rewrite dynamic and cyclic \n",
    "-   .3- motion parameters and gradient \n",
    "\n",
    "-   .4- speed optimization: export time profiling information to Python interface \n",
    "-   .4- speed optimization: now when more voxels in z, it takes about the same time - expected speedup: 8X ! \n",
    "-   .4- speed optimization: primitives to process data in the projection space: add, divide, .. \n",
    "\n",
    "-   .5- fix readme and licenses in all projects, fix PIP \n",
    "-   .5- SPECT: arbitrary volumes, just like PET \n",
    "\n",
    "\n",
    "#### IMPROVEMENTS suggested when presenting Occiput to Ciprian and David: \n",
    "\n",
    "- in IPython notebook, import occiput, numpy: do not import by default \n",
    "- give an error if binning is not consistent: number of projections not equal to the length of the angles array \n",
    "- better naming: use .geometry instead of .binning \n",
    "- use mL instead of mm3\n",
    "- make sure that timing is always in ms - actually it probably is already ms everywhere \n",
    "- fix the bug with osem number of iterations: when the parameter is set to 120 with 120 camera positions, it still does not do MLEM\n",
    "- add the option to export image as mat \n",
    "- warning when the activity volume is too small \n",
    "\n",
    "#### FUNCTIONALITIES\n",
    "\n",
    "- Stefano- Include ACTIVITY_ROI in project_attenuation\n",
    "-       -\tNiccolo- Generate attenuation image from MR \n",
    "-       -\tNiccolo- Optimize angles using pineapple. It should include attenuation and sensitivity \n",
    "-       -\tNiccolo- Reconstruction of brain with attenuation map \n",
    "-       -\tNiccolo- Reconstruct with E7 tools. With/without Scatter - Randoms - Attenuation. \n",
    "-       -     Niccolo/Stefano- Align the MR image with PET - rough\n",
    "-       - \tNiccolo/Stefano- Implement SCATTER and RANDOMS correction - OPOSEM\n",
    "- Stefano- Integrate code that loads azimuthal angles \n",
    "- Stefano- Randoms: create delay sinogram and implement Ordinary Poisson MLEM\n",
    "- Stefano- Bin sinogram with given start and end time in sec or ms \n",
    "-       -\tStefano- Integrate sensitivity in reconstruction code\n",
    "-       -\tStefano- Integrate attenuation in reconstruction code \n",
    "-       -\tStefano- Set N_samples and sample_size to match the diagonal of the image cube\n",
    "- Stefano- Align the MR image with PET: fix the scanner geometry - correct pixel size\n",
    "-       -\tNiccolo- Acquire a De Renzo phantom in different positions of the FOV.\n",
    "- Stefano- Include motion parameters\n",
    "- Stefano- ARC correction\n",
    "- Stefano/David- Variance reduction randoms \n",
    "- Stefano- How to correct for dead times? \n",
    "- Stefano/Niccolo/David- Experiment decaying source for dead-time - at least global \n",
    "-       - \tNiccolo/Stefano- Define data pipeline: scanner/recon/e7/occiput\n",
    "-       - \tNiccolo/Stefano- Implement PSF \n",
    "-       - \tNiccolo/Stefano/Bastien- Implement SCATTER simulation:  \n",
    "-              - 1 - basic wrapper for SSS \n",
    "-              - 2 - Python wrappers of basic functions, such as intersect cylinder with line\n",
    "-              - 3 - create 3 functions for the SSS wrapper\n",
    "-                       1) function that returns the number of scatter points given the attenuation\n",
    "-                       2) function that computes the low resolution sinogram\n",
    "-                       3) function that up-samples the sinogram\n",
    "-              - 4 - add offset for the activity and for the attenuation\n",
    "-              - 5 - remove all exit(); two possibilities: global status; pass status pointer to constructors\n",
    "-              - 6 - set mMR geometry\n",
    "-              - 7 - evaluate mMR cylinder and brain\n",
    "-              - 8 - implement tail fitting (EM)\n",
    "             \n",
    "#### Biograph mMR\n",
    "\n",
    "PET RECONSTRUCTION: \n",
    "\n",
    "- TODO SET TIME WHEN LOADING FROM PROMPTS AND NOT FROM LISTMODE\n",
    "- DONE  Convert dicom list-mode to interfile. \n",
    "- TODO Acquire PET with various bed positions and laser marks. \n",
    "- TODO  Resample hardware uMAP with correct bed position (extract the absolute bed position from the MR data - can it be found anywhere in the PET data? The relative bed position is in the list-mode header). \n",
    "- TODO Decode cardiac gating information in list-mode file \n",
    "- TODO Compare gating information in list-mode file, gating dicom file and gating interfile \n",
    "- TODO Test Spencer’s scatter simulator \n",
    "- TODO Normalization: find out how it is stored / Compressed\n",
    "- TODO Estimate the sensitivity from cylinder data \n",
    "- TODO Implement DEAD-TIME correction - ask Spencer about the saturation curve\n",
    "- TODO Acquire data (Spencer acquired it in the past) to test dead-time correction \n",
    "- TODO Implement ARC correction \n",
    "- TODO Implement DECAY correction \n",
    "- TODO What do the 8 values of the PSF mean? \n",
    "- TODO Implement reconstruction with PSF \n",
    "- TODO Re-calculate the azimuthal angles\n",
    "\n",
    "PET-MR: \n",
    "\n",
    "- TODO Install WIP 793 (radial VIBE)\n",
    "- TODO Inject list-mode packet from MEMPRAGE and WIM 793 \n",
    "\n",
    "NOTES: \n",
    "\n",
    "The relative table position is stored in the header of the list-mode file; this is the bed translation relative to its position at the time of the laser mark. The position of the table at the time of the laser mark is stored somewhere in the MR data (is it stored in the PET data??).  \n",
    "The data EXPORTED from the scanner includes 4 files (all in Dicom format): \n",
    "listmode \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
